package com.utis;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class SortScore {

    public static void main(String[] args) {

        float[][] scoreInfo = new float[3][4];

        scoreInfo[0]  = new float[]{1,80,80,70};
        scoreInfo[1]  = new float[]{2,80,90,70};
        scoreInfo[2]  = new float[]{3,80,70,70};

        System.out.println(Arrays.toString(sortScore(scoreInfo)));

    }


    public static float[][] sortScore(float[][] scoreInfo){

        int arraySize = scoreInfo.length;
        //初始化用来存储结果的二维数组
        float[][] scoreResult = new float[arraySize][5];

        for (int i = 0; i < scoreInfo.length; i++) {
            float sum_score = 0.0f;
            for (int j = 0; j < scoreInfo[i].length; i++) {
                //把结果存入5列数组中
                scoreResult[i][j]=scoreInfo[i][j];
                if (j > 0){
                    sum_score += scoreInfo[i][j];
                }
            }
            scoreResult[i][4]=sum_score;
        }


        //对5列二维数组进行冒泡排序
        for (int i = 0; i < scoreResult.length; i++) {
            for (int j = 0; j < scoreResult[i].length; i++) {
                for(int k=0;k<scoreResult[i].length-j-1;j++) {//-1为了防止溢出
                    if(scoreResult[i][k]>scoreResult[i][k+1]) {
                        float temp = scoreResult[i][k];
                        scoreResult[i][k]=scoreResult[i][k+1];
                        scoreResult[i][k+1]=temp;
                    }
                }


            }
        }
        return scoreResult;
    }


}
